import time

from selenium.webdriver.common.by import By

from common.base import Base
from common.functions import open_browser
from page.frontpage.login_pageX import LoginPage


class Browse(Base,LoginPage):
    # 登录到主页面
    def login(self):
        self.max_window()
        self.get_index()
        self.input_username('srx')
        self.input_password('123456')
        self.login_button()
        time.sleep(2)

    # 浏览主页商品
    def browse_index(self):
        self.click((By.LINK_TEXT,'首页'))
        time.sleep(2)
        # 页面浏览滑到底部
        self.browser_smooth()
        time.sleep(2)
        # 平缓滑倒顶部
        self.slide_up()
        time.sleep(2)
        # 查看商品
        self.click((By.XPATH,"//div/img[@alt='智能相机']"))
        time.sleep(2)
        # 页面后退返回到首页
        self.back()
        time.sleep(2)

    def browser_clothes(self):
        # 点击服装，浏览服装栏
        self.click((By.LINK_TEXT, '服装'))
        time.sleep(2)
        # 滑到底部
        self.browser_smooth()
        time.sleep(2)
        # 滑到顶部
        self.slide_up()
        time.sleep(2)
        # 查看服装页面的商品
        self.click((By.XPATH,"//div/a/img[@alt='短袖POLO衫...']"))
        time.sleep(2)
        # 页面后退返回到上一页
        self.back()
        self.back()


if __name__ == '__main__':
    b1=Browse(browser=open_browser())
    b1.login()
    b1.browse_index()
    b1.browser_clothes()
    b1.quit()
